<template>
	<el-card class="form-container">
		<el-form :model="editForm" ref="editForm" :rules="dataRule" @keyup.enter.native="dataFormSubmitHandle()" label-width="90px">
			<el-form-item label="活动名称" prop="seckillName">
				<el-input v-model="editForm.seckillName" placeholder="请输入秒杀活动名称"></el-input>
			</el-form-item>
			<el-form-item label="开始时间" prop="startDate">
				<el-date-picker
					v-model="editForm.startDate"
					type="date"
					placeholder="选择开始时间"
					format="yyyy 年 MM 月 dd 日"
					:picker-options="pickerTimeOptions">
				</el-date-picker>
			</el-form-item>
			<el-form-item label="结束时间" prop="endDate">
				<el-date-picker
					v-model="editForm.endDate"
					type="date"
					placeholder="选择结束时间"
					format="yyyy 年 MM 月 dd 日"
					:picker-options="pickerTimeOptions">
				</el-date-picker>
			</el-form-item>
			<el-form-item label="上线/下线" prop="onlineStatus">
				<el-radio-group v-model="editForm.onlineStatus">
					<el-radio :label="1">上线</el-radio>
					<el-radio :label="2">下线</el-radio>
				</el-radio-group>
			</el-form-item>
			<el-form-item>
				<el-button @click="cancel">取消</el-button>
				<el-button type="primary" @click="update('editForm')">确定</el-button>
			</el-form-item>
		</el-form>
	</el-card>
</template>

<script>
	import { findSeckillDetail,editSeckill } from '@/api/activity/seckill'
	export default {
		name: 'user-seckill',
		data() {
			return {
				editForm: {
					id:'',
					seckillName: '',
					startDate: '',
					endDate: '',
					onlineStatus: '',
				},
				dataRule: {
					seckillName: [{
							required: true,
							message: '请输入秒杀活动名称',
							trigger: 'blur'
						},
					],
					startDate: [{
							required: true,
							message: '请输入秒杀开始时间',
							trigger: 'blur'
						},
					],
					endDate: [
						{ required: true, message: '请输入秒杀结束时间', trigger: 'blur'},
					],
				},
				pickerTimeOptions: {
					disabledDate(time) {
						return time.getTime() < Date.now();
					},
				},
			}
		},
		created() {
			this.editForm.id = this.$route.query.id
			this.view(this.$route.query.id)
		},
		methods: {
			view(val) {
				findSeckillDetail(val).then(res => {
					this.editForm = res.data.responseData
				})
			},
			cancel() {
				this.$router.go(-1)
			},
			update() {
				const set = this.$refs;
				set['editForm'].validate((valid) => {
					if (!valid) {
						return false
					}
					editSeckill(this.editForm).then(res => {
						if(res.data.responseCode == '200'){
							this.$notify({
								title: '修改成功',
								message: '修改成功',
								type: 'success',
								duration: 2000,
								onClose: this.$router.go(-1)
							})
						}
					})
				})
			}
		}
	}
</script>

<style>
</style>
